export interface CnTreeNode<T> {
  children?: T[];
}

export const traverseTree = <T extends CnTreeNode<T>>(root: T, consumer: (node: T) => void) => {
  consumer(root);
  const children_ = root.children;
  if (children_) {
    children_.forEach(child => {
      if (child) {
        traverseTree(child, consumer);
      }
    });
  }
};
